
package com.wyzz.hr.action;

import java.util.Date;

import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.bo.IInformationBo;
import com.wyzz.hr.pojo.Information;
import com.wyzz.hr.spring.SpringBeanFactory;

public class InfoAction {

	public InfoAction() {
	}

	private void setIInformationBo() {
		infoBo = (IInformationBo) SpringBeanFactory.getBean("informationBo");
	}

	public String addInformation(Information info) {
		String flt = DWRUtil.checkAuth("searchInfo", "execute");
		if ("error".equalsIgnoreCase(flt))
			return "NOAUTH";
		setIInformationBo();
		info.setInfoContent(info.getInfoContent().replace("/n/n", "<br><br>"));
		if (infoBo.saveObject(info))
			return String.valueOf(info.getId());
		else
			return "FAIL";
	}

	public String delInformation(String infoId) {
		String flt = DWRUtil.checkAuth("searchInfo", "execute");
		if ("error".equalsIgnoreCase(flt))
			return "NOAUTH";
		setIInformationBo();
		Information info = infoBo.loadOne(infoId);
		if (info != null)
			return infoBo.deleteInfo(info) ? "SUCC" : "related";
		else
			return null;
	}

	public String updateInformation(Information info) {
		String flt = DWRUtil.checkAuth("searchInfo", "execute");
		if ("error".equalsIgnoreCase(flt))
			return "NOAUTH";
		setIInformationBo();
		Information tmpInfo = infoBo.loadOne(info.getId());
		if (tmpInfo != null) {
			tmpInfo.setInfoTitle(info.getInfoTitle());
			tmpInfo.setInfoBreif(info.getInfoBreif());
			tmpInfo.setInfoContent(info.getInfoContent());
			tmpInfo.setInfoStatus(info.getInfoStatus());
			tmpInfo.setInfoLastChangeTime(new Date());
			if (infoBo.updateInfo(tmpInfo))
				return "SUCC";
		}
		return "FAIL";
	}

	private static final long serialVersionUID = 0xc53a77b0ae03eebfL;
	protected static final String SUCC = "SUCC";
	protected static final String FAIL = "FAIL";
	protected static final String NOAUTH = "NOAUTH";
	private IInformationBo infoBo;
}
